package com.posjiajia.user.api.controller;

import com.posjiajia.user.core.params.OrganQueryParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.posjiajia.commom.utils.vo.result.BaseResult;
import com.posjiajia.user.core.bo.OrganBo;
import com.posjiajia.user.core.bo.UserBo;
import com.posjiajia.user.core.vo.OrganVo;

import java.util.List;

/**
 * @author zhenhua.sun
 * @title com.posjiajia.user.api.controller
 * @date 9/17/16
 */
@Controller
@RequestMapping("/organ")
public class OrganController {

    private static final Logger logger = LoggerFactory.getLogger(UserBo.class);

    @Autowired
    private OrganBo organBo;

	@RequestMapping(value = "/{organId}", method = RequestMethod.GET)
    @ResponseBody
	public BaseResult getOrganByUserToken(@PathVariable String organId) {
		BaseResult success = new BaseResult(BaseResult.SUCCESS);

        try {
			OrganVo organVo;
			organVo = organBo.get(Integer.parseInt(organId));
			success.putData("organ", organVo);

        }catch (Exception e){
            logger.error("query organ error",e);
        }

		return success;
    }

    @RequestMapping(value = "list",method = RequestMethod.GET)
    @ResponseBody
    public BaseResult queryList(OrganQueryParam param){
        BaseResult success = new BaseResult(BaseResult.SUCCESS);
        try {
            List<OrganVo> voList = organBo.query(param);
            success.putData("organList",voList);
        }catch (Exception e){
            logger.error("query organ list error",e);
        }
        return success;
    }
}
